package com.qinsoft.business.task.dao;

import org.apache.ibatis.session.SqlSession;

import com.qinsoft.business.task.bean.Task;
import com.qinsoft.frame.messages.WriteMessage;
import com.qinsoft.frame.utils.DbUtil;


public class TaskDao
{
    public Task select(String taskType)
    {
        SqlSession sqlMap = null;
        Task task = new Task();
        try 
        {
            //获取连接对象
            sqlMap= DbUtil.getSqlMapClient();
            //执行查询方法
            task = sqlMap.selectOne("com.qinsoft.business.task.sqlMap.task.select",taskType);
        }
        catch (Exception e) 
        {
            WriteMessage.WriteErrorLog(this.getClass().toString()+".select("+ taskType +")", e);
        }
        finally
        {
            sqlMap.close();
        }
        return task;
    }
    
    public Boolean exist(String taskType)
    {
        Boolean flag = false;
        SqlSession sqlMap = null;
        try 
        {
            //获取连接对象
            sqlMap= DbUtil.getSqlMapClient();
            //执行查询方法
            flag = sqlMap.selectOne("com.qinsoft.business.task.sqlMap.task.exist",taskType);
        }
        catch (Exception e) 
        {
            WriteMessage.WriteErrorLog(this.getClass().toString()+".exist("+ taskType +")", e);
        }
        finally
        {
            sqlMap.close();
        }
        return flag;
    }
    
    public void insert(Task task)
    {
        SqlSession sqlMap = null;
        try 
        {
            //获取连接对象
            sqlMap = DbUtil.getSqlMapClient();
            //执行插入方法
            sqlMap.insert("com.qinsoft.business.task.sqlMap.task.insert",task);
        }
        catch (Exception e) 
        {
            WriteMessage.WriteErrorLog(this.getClass().toString()+".insert()", e);
        }
        finally
        {
            sqlMap.close();
        }
    }
    
    public void delete(Long taskId)
    {
        SqlSession sqlMap = null;
        try 
        {
            //获取连接对象
            sqlMap = DbUtil.getSqlMapClient();
            //执行删除方法
            sqlMap.delete("com.qinsoft.business.task.sqlMap.task.delete",taskId);
        }
        catch (Exception e) 
        {
            WriteMessage.WriteErrorLog(this.getClass().toString()+".delete("+ taskId +")", e);
        }
        finally
        {
            sqlMap.close();
        }
    }
}
